package controller;

import config.Interceptor.PassToken;
import entity.Usershoppingcat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import service.impl.Usershopppingcatserviceimpl;
import utils.CommonRetumType;

import javax.annotation.Resource;
import java.net.InetSocketAddress;

@RestController
@RequestMapping("/usershoppingcat")
public class Usershoppingcatcontroller {

    @Resource
    Usershopppingcatserviceimpl usershopppingcatserviceimpl;


    @GetMapping("/listcat")
    @PassToken
    public CommonRetumType listcat(@RequestParam(value = "id",required = true) Integer id)
    {
        return  CommonRetumType.create(usershopppingcatserviceimpl.listbycat(id),"购物车查询成功");
    }

    @GetMapping("/addcatshop")
    @PassToken
    public CommonRetumType addcatshop(@RequestParam(value = "userid",required = true) Integer userid,
                                      @RequestParam(value = "addressid",required = true) Integer addressid,
                                      @RequestParam(value = "shoppinglistid",required = true) Integer shoppinglistid)
    {

        Usershoppingcat usershoppingcat = new Usershoppingcat();
        usershoppingcat.setUserid(userid);
        usershoppingcat.setAddressid(addressid);
        usershoppingcat.setShoppinglistid(shoppinglistid);
        usershoppingcat.setBuy(0);
        int result =  usershopppingcatserviceimpl.insertSelective(usershoppingcat);
        return CommonRetumType.create(result,"购物车添加成功");
    }
}
